import facade
from xjlibrary.our_file_dir import BaseDir

curPath = BaseDir.get_file_dir_absolute(__file__)
topPath = BaseDir.get_upper_dir(curPath, -2)
sPath = BaseDir.get_new_path(topPath, "download", "adks_cqjd", "download", "home")
BaseDir.create_dir(sPath)


class DOwnHome(object):
    def __init__(self):
        self.baseurl = "http://202.202.244.23/Course?year=0&cataType=xsbg&orderByType=1&pageLayout=1&PageIndex={}&pageSize=1000"
        self.proxys = {
            "http": "192.168.30.176:8171",
            "https": "192.168.30.176:8171"
        }

    def downhome(self):
        # 这是学术报告的
        # 共16页 如果页面增加请手动修改
        for i in range(1, 17):
            url = self.baseurl.format(i)
            BoolResult, errString, r = facade.BaseRequest(url, proxies=self.proxys, timeout=30)
            if BoolResult:
                BaseDir.single_write_file(r.text, BaseDir.get_new_path(sPath, "xsbg"+str(i) + ".html"))
            else:
                print("下载失败，请检查")

    def downhome2(self):
        # 这是学术鉴赏的
        url = "http://202.202.244.23/Course?year=0&cataType=xsjs&orderByType=1&pageLayout=1&PageIndex={}&pageSize=1000"
        for i in range(1, 7):
            fullurl = url.format(i)
            BoolResult, errString, r = facade.BaseRequest(fullurl, proxies=self.proxys, timeout=30)
            if BoolResult:
                BaseDir.single_write_file(r.text, BaseDir.get_new_path(sPath, "xsjs"+str(i) + ".html"))
            else:
                print("下载失败，请检查")


if __name__ == "__main__":
    down = DOwnHome()
    # down.downhome()
    down.downhome2()